package com.lagou;

import com.lagou.entity.Employee;
import com.lagou.repository.EmployeeRepository;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import java.util.Date;
import java.util.Random;

@SpringBootApplication
public class MongodbMain {

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(MongodbMain.class, args);
        EmployeeRepository employeeRepository = context.getBean(EmployeeRepository.class);

        Random random = new Random();
        for(int i=0;i<1000;i++) {
            Employee employee = new Employee();
            employee.setName("test" + (1000 + i));
            employee.setBirthday(new Date());
            employee.setExpectSalary((i + 1) * random.nextDouble());
            employee.setCity("guangzhou");

            employeeRepository.insert(employee);
            System.out.println("插入成功");
        }

        System.out.println("开始查询");
        employeeRepository.findAll().forEach(employee -> System.out.println(employee));
        System.out.println("结束查询");
    }
}
